package net.mysoft.budgetsoft.system.security;

import java.util.HashMap;
import java.util.Map;

import javax.annotation.Resource;

import net.mysoft.budgetsoft.system.service.LoginService;

import org.apache.log4j.Logger;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.core.userdetails.User;
import org.springframework.security.core.userdetails.UserDetails;
import org.springframework.security.core.userdetails.UserDetailsService;
import org.springframework.security.core.userdetails.UsernameNotFoundException;
import org.springframework.stereotype.Component;

@Component("securityUserService")
public class SecurityUserServiceImpl implements UserDetailsService{
	/**
	 * Logger for this class
	 */
	private static final Logger log = Logger.getLogger(SecurityUserServiceImpl.class);
	
	@Autowired
	private LoginService loginService;

	@Override
	public UserDetails loadUserByUsername(String username)
			throws UsernameNotFoundException {
		log.info("loadUserByUsername...invoke...");
		log.info("username="+username);
		Map<String, Object> paramMap = new HashMap<String, Object>();
		paramMap.put("userId", username);
		//User user = loginService.check(name, pwd)
		//Collection<GrantedAuthority> auths=new ArrayList<GrantedAuthority>();
		//user.getRoles();
		/*GrantedAuthority auth2=new SimpleGrantedAuthority("ROLE_ADMIN");
        auths.add(auth2);
        if(username.equals("robin1")){
            auths=new ArrayList<GrantedAuthority>();
            GrantedAuthority auth1=new SimpleGrantedAuthority("ROLE_ROBIN");
            auths.add(auth1);
        }*/
        
//        User(String username, String password, boolean enabled, boolean accountNonExpired,
//                    boolean credentialsNonExpired, boolean accountNonLocked, Collection<GrantedAuthority> authorities) {
       /* User user = new User(username,
                "robin", true, true, true, true, auths);*/
		return null;
	}

}
